﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace DBToExcel
{
    public partial class Loading : Form
    {
        Control owner;


        public Loading(Control ow)
        {
            InitializeComponent();
            if (ow != null)
            {
                this.Width = ow.Width;
                this.Height = ow.Height;
                owner = ow;
            }
           
            this.skinProgressIndicator1.Location = new Point(this.Width / 2 - this.skinProgressIndicator1.Width / 2, this.Height / 2 - this.skinProgressIndicator1.Height / 2);
            CheckForIllegalCrossThreadCalls = false;
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Pen labelBorderPen;
            SolidBrush labelBackColorBrush;
            Color cl = Color.FromArgb(125, this.BackColor);
            labelBorderPen = new Pen(cl, 0);
            labelBackColorBrush = new SolidBrush(cl);

            base.OnPaint(pe);
            pe.Graphics.DrawRectangle(labelBorderPen, 0, 0, this.Width, this.Height);
            pe.Graphics.FillRectangle(labelBackColorBrush, 0, 0, this.Width, this.Height);
        }
        public static void ShowLayer(Control control, Action action)
        {
            Loading load = new Loading(control);
            load.Show(control);
            if (action != null)
            {
                action.BeginInvoke(new AsyncCallback(x =>
                {
                    load.Close();
                    load.Dispose();
                }), null);
            }
        }

        private void Loading_Load(object sender, EventArgs e)
        {
            if (owner!=null)
            {
                this.Location = new Point(owner.Left, owner.Top);
            }
        }
    }
}
